#pragma once

#include <QtWidgets/QPushButton>
#include <QtWidgets/QLabel>
#include <QtWidgets/QWidget>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QGroupBox>
#include <QtNetwork/QTcpSocket>
#include <QtCore/QTimer>

class TcpClient :
    public QWidget
{
    Q_OBJECT

public:
    TcpClient(QString, int, QWidget* parent = nullptr);
    ~TcpClient();

private:
    QPushButton* btn_start = nullptr, * btn_stop = nullptr, * btn_send = nullptr;
    QGridLayout* mainLayout = nullptr,
        * top_layout = nullptr,
        * bottom_layout = nullptr,
        * center_layout = nullptr;
    QGroupBox* centerBox = nullptr, * topBox = nullptr, * bottomBox = nullptr;

    QLabel* lb_status = nullptr, * lb_port = nullptr,*lb_rip=nullptr,*lb_rport=nullptr;
    QTextEdit* t_receive = nullptr, * t_send = nullptr;

    QTcpSocket* socket = nullptr;

    QTimer timer;
    int t=0;

    QString ip;
    int port;

    void initServer(QString,int);
    void initGUI();

    void On_Stop();
    void On_Start();
    
    void On_Received();
    void On_Send();
};

